home *** CD-ROM | disk | FTP | other *** search
- /* Platform sprite, moveable version, not faceless */
- /* */
-
- #include "SAT.h"
- #include "myPlatform.h"
-
- #ifndef abs
- #define abs(x) (x>0?x:-x)
- #endif
-
- #define MovPlatformSpeed 2
-
- /*************** In platformSAT.h *****************\
- * #define MaxV(me) (*(MovPlatP)me->appPtr).MaxV
- * #define MinV(me) (*(MovPlatP)me->appPtr).MinV
- *
- * typedef struct {
- * short MaxV,MinV;
- * short MaxX,MinX;
- * short filled; //unused
- * } MovPlatRec,*MovPlatP;
- *********************************************/
- FacePtr platFace;
-
- void InitMovPlatform()
- {
- platFace = SATGetFace(139);
- }
-
- pascal void SetupMovPlatform(SpritePtr me)
- {
- Rect r;
- PolyHandle pol;
-
- me->speed.v =-MovPlatformSpeed + SATRand(2) * 2;
- me->face = platFace;
- me->appPtr = NewPtr(sizeof(MovPlatRec));
- if (me->appPtr) {
- (*(MovPlatP)me->appPtr).MaxV =me->position.v;
- (*(MovPlatP)me->appPtr).MinV =me->kind;
- }
- SetRect(&me->hotRect, 0, 3, 60, 20);
- me->task = &HandleMovPlatform;
- me->hitTask = (void *)&HitMovPlatform;
- }
-
- pascal void HandleMovPlatform(SpritePtr me)
- {
- me->position.v += me->speed.v;
- if(me->position.v < MinV(me)) me->speed.v =MovPlatformSpeed;
- if(me->position.v > MaxV(me)) me->speed.v =-MovPlatformSpeed;
-
- if(me->speed.v == 0){
- if (me->position.v > (MaxV(me)-MinV(me)) / 2)
- me->speed.v = -MovPlatformSpeed;
- else
- me->speed.v = MovPlatformSpeed;
- }
-
- me->layer = -1*(me->position.v);
- }
-
- pascal void HitMovPlatform(SpritePtr me, PlSpritePtr him)
- {
- int mini, i, min;
- int diff[5];
-
- if(him->task == (void *)HandlePlayerSprite) {
- diff[1] =-me->hotRect2.top + (him->hotRect2.bottom); /* (T)toB */
- diff[2] =-him->hotRect2.top + (me->hotRect2.bottom); /* (B)toT */
- diff[3] =-me->hotRect2.left + (him->hotRect2.right); /* LtoR */
- diff[4] =-him->hotRect2.left + (me->hotRect2.right); /* RtoL */
- mini = 0;
- min = 10000;
- for(i =1; i <= 4; i++)
- if(min > diff[i]){
- min = diff[i];
- mini = i;
- }
- switch(mini){
- case 1: /*floor*/
- him->action = Stand;
- him->position.v = him->position.v - diff[1] + 2;
- if(him->speed.v > 0)
- him->speed.v = 0;
- him->speed.h = 0;
- break;
- case 2: /* ceiling */
- him->position.v = him->position.v + diff[2] + 1;
- if(him->speed.v < 0)
- him->speed.v = (him->speed.v)*(-1);
- break;
- case 3: /*left*/
- him->position.h = him->position.h - diff[3] - 1;
- if(him->speed.h > 0)
- him->speed.h = (him->speed.h)*(-1);
- break;
- case 4: /*right*/
- him->position.h =him->position.h + diff[4] + 1;
- if(him->speed.h < 0)
- him->speed.h = (him->speed.h)*(-1);
- break;
- } /* switch */
- } /* if */
- }
-